package part7threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @description: Executors.newScheduledThreadPool(1)
 * @author: sali
 * @date: 2024/3/30 14:10.
 * @version: 1.0
 */
public class ThreadPoolTest08 {

    public static void main(String[] args) {
        // 创建一个给定初始延迟的间隔性的任务，之后的下次执行时间是上一次执行从执行到结束所需要时间+给定的间隔时间
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        scheduledExecutorService.scheduleWithFixedDelay(() -> {
            System.out.println("current Time" + System.currentTimeMillis());
            System.out.println(Thread.currentThread().getName() + "正在执行");
        }, 1, 3, TimeUnit.SECONDS);
    }

}
